import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
const Printer 	= $Lazy.hook(()=>import('#private/printer'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		selectedRows:[],
		copies: 1,	// 打印数量
		// 搜索表单列表
		forms : [
			{ label: '打印数量',		name: 'copies', value: 1, type:'number',
				onValue: ({value,ref}) => {
					if(parseInt(value)<=0){
						this.setState({copies:1})
						setTimeout(()=> ref.setValue({ copies: 1}) )
					}else{
						this.setState({copies:value})
					}
				}
			},
			{ label:' ', 			tag: '批量打印', 	type: 'checkbox', colon:false, 	onValue:({value})=>{
				const { forms } = this.state
				$fn.hideRows(forms,['spec_start','spec_end'], !value)
				$fn.hideRows(forms,'spec_number', value)
				this.setState({ forms })
			} },
			{ label: '条码号',		name: 'spec_number',  		},
			{ label: '开始条码',		name: 'spec_start',  	hide: true,		min:12,	max:14,},
			{ label: '结束条码',		name: 'spec_end',  		hide: true,		min:12,	max:14},
			{ label: '标本架代码',	name: 'sf_code',	 },
		],
	}
	componentDidMount(){
		// this.fetch()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'receive/printlists' )
	// 表单
	cols = [
		{ title: '标本条码号', 		dataIndex: 'spec_code', 		...$fn.table.spec_code },
		{ title: '病人姓名', 		dataIndex: 'patient_name', 		...$fn.table.name },
		{ title: '检测项目', 		dataIndex: 'kind_name', 		width:180 },
		{ title: '实验号', 			dataIndex: 'lb_tpl', 			...$fn.table.spec_code },
		{ title: '岗位', 			dataIndex: 'job_id', 			width:100 },
		{ title: '科室', 			dataIndex: 'team_name', 		width:100 },
		{ title: '标本架代码', 		dataIndex: 'sf_code', 			...$fn.table.spec_code },
		{ title: '标本类型', 		dataIndex: 'spec_type_name',	width:130 },
		{ title: '标本接收时间', 	dataIndex: 'sp_receive_time',  	...$fn.table.time},
	]
	
	// 操作按钮
	controls = () => {
		const { copies,selectedRows } = this.state
		return [
			Controls.click.call(this, '打印实验号标签', ()=> {
				this.printerRef.printer({ code: 50104, data:selectedRows, loading:false, link:copies})
			},{isKeys:1})	// 打印实验号标签		 	
		]
	}
		
	render(){
		return (
			<>
				<Page title='打印实验号'  controls={this.controls()}>
					{/* 搜索 */}
					{ SearchForm.call(this) }
					{/* 表格 */}
					{ Table.call(this) }
				</Page>
				{/* 打印 */}
				<Printer onRef = { ref => this.printerRef = ref } hasBtn = {false}  />
			</>
		)
	}
}

export default Index